package com.sias.beanfactorypostprocessor;

import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

/**
 * @author 吴文杰
 * @version 1.0
 * @since 2023/5/31 23:36
 */
@Configuration
@ComponentScan("com.sias.beanfactorypostprocessor.component")
public class Config {

  @Bean
  public Bean1 bean1(){
    return new Bean1();
  }

  @Bean
  public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource){
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);
    return sqlSessionFactoryBean;
  }

  @Bean(initMethod = "init")
  public DataSource dataSource(){
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mysql://localhost:3306/exam");
    dataSource.setUsername("root");
    dataSource.setPassword("root");
    return dataSource;
  }
}
